import requests  
import subprocess  
from functools import partial  
import json  
import time  
import execjs  

subprocess.Popen = partial(subprocess.Popen, encoding='utf-8')  

with open('./调试.js', 'r', encoding='utf-8') as f:  
    js = f.read()  

js_com = execjs.compile(js)  

headers = {  
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0',  
}  

params = {  
    'query': 'newest',  
    'page': '4',  
    'size': '30',  
    'keyv': '24.11.06',  
    'ivd': 'iE9mRBVK28nWdEWwwp2i1w43SJW92mkhnrvC1AViUKPRMBFm5FIdDItlwACfBWKcAuTXXZcdpK4t3bXmCxTvNqhr39UIL9ioFNSJuf6XJhFkHtq4gSg3uIDBoNtlAo9FgTgZNIldGjsU+6cgGg3+YzNR4msXv8Yk1KCORk5QgmzJcB9P7BAKUhQnhsi16pOj74EAqoCaMKAidjM+kV8k0GRP7xYOdUjTxl+v+RH31vNLMDNq0nViy7DJS+BY0KAp36hcBNDRYmWUgz7SvadrgpU6eNFMwiMglpv+C3GtAZO0WAPJHVOwmM26aKX8GtdcnklQnwtvqngybf/Qy8WIzg==',  
}  

dict_data = {  
    'page': params['page'],  
    'query': params['query'],  
    'size': params['size'],  
    'timestamp': str(int(time.time()))  
}  

dd = json.dumps(dict_data)  

print(dd)  

sign = js_com.call('getIvd', dd)  
print(sign)  

params['ivd'] = sign  

response = requests.get('https://segmentfault.com/gateway/questions', params=params, headers=headers)  

print(response.status_code)  
print(response.json())